package android.slc.appbase.ui.vd;

import android.os.Bundle;
import android.slc.core.vm.SingleLiveEvent;

import java.io.Serializable;

/**
 * 基础常用的盒子vm
 *
 * @author slc
 * @date 2020/12/29 10:37
 */
public abstract class BaseCommonPageShelfVmBox extends BaseDataChangeVmBox implements BaseRegisterActivityFunc.IIntegrationRegisterActivityFunc {
    public SingleLiveEvent<Bundle> showAddUiOf = new SingleLiveEvent<>();
    private BaseRegisterActivityFunc.IntentTargetWrapper intentTargetWrapper;
    public final BaseRegisterActivityFunc<Serializable> addRegisterActivityFunc;

    public BaseCommonPageShelfVmBox() {
        this.addRegisterActivityFunc = createActionRegisterActivityFunc();
        if (this.addRegisterActivityFunc != null && this.addRegisterActivityFunc.getOnTargetActivityResultCallback() == null) {
            this.addRegisterActivityFunc.setOnActivityResultCallback(new SimpleRegisterActivityFunc.OnActivityResultCallback<Serializable>() {
                @Override
                public void onIntentData(Serializable data) {
                    BaseCommonPageShelfVmBox.this.notifyRefreshByGlobal(data);
                }

                @Override
                public void onIntentBundle(Bundle data) {
                    BaseCommonPageShelfVmBox.this.onActivityResult(data);
                }
            });
        }
    }

    @Override
    public BaseRegisterActivityFunc<Serializable> createActionRegisterActivityFunc() {
        return new SimpleRegisterActivityFunc<>(getGotoTargetActivityItw());
    }

    /**
     * 获取item点击后要取得activityClass
     *
     * @return
     */
    @Override
    public final BaseRegisterActivityFunc.IntentTargetWrapper getGotoTargetActivityItw() {
        if (intentTargetWrapper == null) {
            intentTargetWrapper = createGotoTargetActivityItw();
        }
        return intentTargetWrapper;
    }

    protected BaseRegisterActivityFunc.IntentTargetWrapper createGotoTargetActivityItw() {
        return null;
    }

    /**
     * 显示添加界面
     */
    public void showAddUi() {
        showAddUiOf.call();
    }
}
